home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / Snippets / Devices / Wake100 / Wake100.c next >
Encoding:
C/C++ Source or Header  |  1992-09-01  |  1.2 KB  |  59 lines  |  [TEXT/MPS ]

  1. //
  2. //
  3. // © Copyright 1991 Apple Computer, Inc.  All Rights Reserved
  4. //
  5. // By Ricardo Batista
  6. //
  7. // This is an INIT which reads the wake up time in the PowerBook 100 and
  8. // old Portable, if the wake up date has elapsed then we add a day to it
  9. // so that the machine wakes up at the same time every day.
  10. // By request of Neal Macklin.  Maybe we can make something useful from
  11. // this later on.
  12. //
  13. //  This file is a code resource that gets added to the sleep queue.
  14.  
  15.  
  16. #include <Types.h>
  17. #include <Power.h>
  18. #include <OSUtils.h>
  19.  
  20. typedef unsigned long         ulong;
  21.  
  22.  
  23.  
  24. long main()
  25. {
  26.     DateTimeRec d;
  27.     ulong wTime, now;
  28.     Boolean wake = false;
  29.     short err;
  30.     short hour, minute;
  31.     
  32.     err = GetWUTime((long*) &wTime, (Byte*) &wake);
  33.     if (err)
  34.         return(0L);
  35.     GetDateTime(&now);
  36.     now += 2L;                    // add 2 secs to make sure we just woke up
  37.     if (now > wTime) {
  38.         Secs2Date(wTime, &d);    // get day time they wanted
  39.         hour = d.hour;
  40.         minute = d.minute;
  41.         Secs2Date(now, &d);        // get current date
  42.         if (hour < d.hour)
  43.             d.day++;            // next day
  44.         if ((hour == d.hour) && (minute <= d.minute))
  45.             d.day++;
  46.         d.hour = hour;
  47.         d.minute = minute;
  48.         Date2Secs(&d, &wTime);
  49.         err = SetWUTime((long) &wTime);    // interfaces have a bug !
  50.     }
  51.     
  52.     return(0L);
  53. }
  54.  
  55.  
  56.  
  57.  
  58.  
  59.